----local cjson = require "cjson"
--local hash = redis.call('HGETALL', KEYS[1])
--local result = {}
--for i = 1, #hash, 2 do
--    result[hash[i]] = hash[i + 1]
--end
--return cjson.encode(result)

local zsetKey = "chat_group:group_users:groupID_" .. ARGV[1]
local firstTimestamp = tonumber(ARGV[2])
local secondTimestamp = tonumber(ARGV[3])
local args = {}
for i = 1, #KEYS do
    if i == 1 then
        table.insert(args, firstTimestamp)
    else
        table.insert(args, secondTimestamp)
    end
    table.insert(args, KEYS[i])
    local newKey1 = "chat_group:user_group_list:ID_" .. KEYS[i]
    local newKey2 = "chat_group:user_group_object:ID_" .. KEYS[i] .. ":" .. ARGV[1]
    redis.call('ZADD', newKey1, firstTimestamp,ARGV[1])
    redis.call('HSET', newKey2, 'content', ARGV[4])
    redis.call('HSET', newKey2, 'tip', ARGV[5])
    redis.call('HSET', newKey2, 'time', ARGV[6])
end
redis.call('ZADD', zsetKey, unpack(args))

----local cjson = require "cjson"
--local baseKey = "chat:caht_list:ID_" ..  KEYS[1]
--local zsetValues = redis.call('ZRANGE', baseKey, 0, -1, 'REV')
---- 创建一个用于存储结果的表
--local result = {}
---- 遍历 Zset 值，拼接新 keys 并获取哈希值
--for i, value in ipairs(zsetValues) do
--    local newKey = "chat:chat_object:ID_" .. KEYS[1] .. ":" .. value
--    local hashValues = redis.call('HGETALL', newKey)
--    local hashTable = {}
--    for j = 1, #hashValues, 2 do
--        hashTable[hashValues[j]] = hashValues[j + 1]
--    end
--    result[newKey] = hashTable
--end
---- 将结果表转换为 JSON 字符串
--return cjson.encode(result)


--local key1 = "test3:" .. ARGV[1] .. ":" .. ARGV[2]
--local key2 = "test3:" .. ARGV[2] .. ":" .. ARGV[1]
--
--redis.call('HSET', key1, 'name', ARGV[3])
--redis.call('HSET', key1, 'time', ARGV[4])
--
--redis.call('HSET', key2, 'name', ARGV[3])
--redis.call('HSET', key2, 'time', ARGV[4])
--return 'OKk'